package com.create404.suishoupai.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.create404.suishoupai.dto.LikedNewsDto;
import com.create404.suishoupai.entity.NewsLike;
import com.create404.suishoupai.mapper.NewsLikeMapper;
import com.create404.suishoupai.service.INewsLikeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author create404
 * @since 2021-07-17
 */
@Service
public class NewsLikeServiceImpl extends ServiceImpl<NewsLikeMapper, NewsLike> implements INewsLikeService {
    @Autowired
    NewsLikeMapper newsLikeMapper;

    @Override
    public List<NewsLike> isNewsLiked(String newsId, String employeeId) {
        QueryWrapper<NewsLike> wrapper = new QueryWrapper<>();
        wrapper.and(wq -> wq
                .eq("news_id", newsId)
                .eq("employee_id", employeeId));
        return newsLikeMapper.selectList(wrapper);
    }

    @Override
    public Wrapper<NewsLike> deleteNewsLiked(String newsId, String employeeId) {
        QueryWrapper<NewsLike> wrapper = new QueryWrapper<>();
        wrapper.and(wq -> wq
                .eq("news_id", newsId)
                .eq("employee_id", employeeId));
        return wrapper;
    }

    @Override
    public IPage<LikedNewsDto> getLikedNews(Page<?> page, String employeeId) {
        return newsLikeMapper.getLikedNews(page, employeeId);
    }
}
